home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / TimeSpeak ƒ / TimeSpeak.cp < prev   
Text File  |  1993-05-26  |  1KB  |  74 lines

  1. ////////////
  2. //
  3. //    TimeSpeak.cp
  4. //
  5. //    A simple audible clock which speaks the time using voice samples
  6. //    stored as sound resorces in the application.
  7. //
  8. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  9. //
  10. ////////////
  11.  
  12. #include <sound.h>
  13. #include "SpeakStrings.h"
  14.  
  15. void TimeSpeak(void);
  16. static void    Sound(short    sndResID);
  17.  
  18. void TimeSpeak(void)
  19. {
  20.     Boolean    am = true;
  21.     short    hour,minute;
  22.     DateTimeRec    now;
  23.  
  24.     GetTime(&now);
  25.     hour = now.hour;
  26.     if (hour >= 12)
  27.         am = false;
  28.     if (hour > 12)
  29.         hour -= 12;
  30.     minute = now.minute;
  31.     Sound(timeIs);
  32.     Sound(ones[hour]);
  33.     if (minute % 60 )
  34.     {
  35.         if (minute > 19 )
  36.                 {
  37.                     Sound(tens[minute/10]);
  38.                     if (minute % 10)
  39.                         Sound(ones[minute % 10]);
  40.                 }
  41.         else
  42.             Sound(ones[minute]);
  43.         Sound(amFlag[am]);
  44.     }
  45.     else
  46.         Sound(oClock);
  47. }
  48.  
  49. void    Sound(short    sndResID)
  50. {
  51.     SndChannelPtr    mySndChan = nil;
  52.     Handle            mySndHandle;
  53.     Boolean            kAsync = true;
  54.     OSErr            myErr;
  55.     
  56.     mySndHandle = GetResource('snd ',sndResID);
  57.     if (mySndHandle)
  58.     {
  59.         myErr = SndPlay(mySndChan, mySndHandle, kAsync);
  60.         if (myErr)
  61.         {
  62.             FlashMenuBar(0);
  63.             SysBeep(1);
  64.             FlashMenuBar(0);
  65.         }
  66.     }
  67.     else //need a more informative error message here
  68.     {
  69.         FlashMenuBar(0);
  70.         SysBeep(1);
  71.         FlashMenuBar(0);
  72.     }
  73. }
  74.